package ui.control;

import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import ui.filter.EntityFilter;
import ui.filter.StringArrayFilter;
import ui.util.UiUtil;

import com.swtxml.swt.byid.ById;
import com.swtxml.views.SwtXmlComposite;

import de.ralfebert.rcputils.builder.table.format.Formatter;

public class SearchTextComposite extends SwtXmlComposite {
	private final static Logger logger = LoggerFactory
			.getLogger(SearchTextComposite.class);
	@ById
	private Label searchLabel;
	@ById
	private Text searchText;
	@ById
	private Composite comp;

	private StringArrayFilter strFilter;
	private EntityFilter etyFilter;
	private TableViewer tableViewer;

	public SearchTextComposite(Composite parent, int style) {
		super(parent, style);
	}

	public SearchTextComposite(Composite parent, int style,StringArrayFilter filter) {
		super(parent, style);
		this.strFilter = filter;
	}

	public SearchTextComposite(Composite parent, int style, EntityFilter filter) {
		super(parent, style);
		this.etyFilter = filter;
	}

	@Override
	public void setupView() {

	}

	private void keyReleased() {
		tableViewer = UiUtil.getTableViewer();
		if (etyFilter != null) {
//			logger.debug("in the Filter ety:{}", page.getActivePart().toString());
			etyFilter.setSearchText(searchText.getText());
		} 
		else if (strFilter != null) {
			strFilter.setSearchText(searchText.getText());
//			tableViewer.addFilter(strFilter);
		}
		tableViewer.refresh();
		Formatter.setZebraBackground(tableViewer);
	}

//	public void bindValues(DataBindingContext bdc,Class clazz, String property, Object obj){
////	public DataBindingContext bindValues(DataBindingContext bdc,Class clazz, String property, Object obj){
//		IObservableValue myModel = PojoProperties.value(clazz,property).observe(obj);
//		IObservableValue myWidget = WidgetProperties.text(SWT.Modify).observe(searchText);
//		bdc.bindValue(myWidget, myModel);
////		return bdc;
//	}
	

	/**
	 * @return the searchLabel
	 */
	public Label getSearchLabel() {
		return searchLabel;
	}

	/**
	 * @param searchLabel the searchLabel to set
	 */
	public void setSearchLabel(Label searchLabel) {
		this.searchLabel = searchLabel;
	}

	/**
	 * @return the searchText
	 */
	public Text getSearchText() {
		return searchText;
	}

	/**
	 * @param searchText the searchText to set
	 */
	public void setSearchText(Text searchText) {
		this.searchText = searchText;
	}

	/**
	 * @return the comp
	 */
	public Composite getComp() {
		return comp;
	}

	/**
	 * @param comp the comp to set
	 */
	public void setComp(Composite comp) {
		this.comp = comp;
	}
	

}
